<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // get 和 set ： getter 和setter
      // get 是 获取值   set  设置值；
      class Person {
        height = "178cm";
        // name = "张三";
        constructor() {
          // this.name = "张三";
          this.age = 20;
        }

        get name() {
          return "张三";
        }
        set name(newValue) {
          console.log(newValue);
        }

        get weight() {
          console.log("获取体重值。。。。");
          return "100kg";
        }
        set weight(newValue) {
          console.log("一旦设置了 weight值会触发set函数", newValue);
        }
      }

      let zhangsan = new Person();
      console.log(zhangsan);
      // zhangsan.weight   //获取weight的值；
      zhangsan.weight = "90kg";

      // 总结： es6的类里设置属性  ： 1.this.name  2 写在类里  3.get和set来获取或者设置属性
    </script>
  </body>
</html>
